﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace MbWsClient
{
    public static class GeneralHelpers
    {
        public static void EnsureDirectoryExistance(this DirectoryInfo dir)
        {
            if (!Directory.Exists(dir.FullName))
            {
                Directory.CreateDirectory(dir.FullName);
            }
        }

        public static T ToEnum<T>(this string value) where T : struct
        {
            object retVal = System.Enum.Parse(typeof(T), value);
            return (T)retVal;
        }

        public static int IndexWhere<T>(this IEnumerable<T> array, Func<T, bool> function)
        {
            int retVal = -1;
            int count = 0;
            foreach (T obj in array)
            {
                if (function(obj))
                {
                    retVal = count;
                    break;
                }
                count++;
            }
            return retVal;
        }
    }
}
